home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / window / ultrawin / uwdemo / uw_demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  44.8 KB  |  1,354 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* UW_DEMO.C                                                                                                                            */
  4. /*                                                                                                                    Kevin Huck            */
  5. /*                                                                                                                    Boyd Gafford        */
  6. /*                                                                          */
  7. /*   This demo program will show you many of the capabilities of UltraWin   */
  8. /* version 2.10.  See the documentation for a complete function listing.    */
  9. /*                                                                          */
  10. /* NOTE:                                                                    */
  11. /*   We have provided a BLDDEMO.BAT file which will rebuild both this       */
  12. /*   UW_DEMO.C file and the STR_DEMO.C file for the Turbo, Borland, and     */
  13. /*   Microsoft C compilers. This demo requires the UltraWin 2.10 large      */
  14. /*   model library.  If you have not ordered UltraWin and only have the     */
  15. /*   small model libraries, but want to use a demo to test out your first   */
  16. /*   project, try STR_DEMO.C.                                               */
  17. /*                                                                          */
  18. /****************************************************************************/
  19. #include <stdlib.h>
  20. #include <dos.h>
  21. #include <stdio.h>
  22. #include <ctype.h>
  23.  
  24. #ifdef M_I86
  25.     #include <malloc.h>
  26.     #include <graph.h>
  27. #else
  28.     #include <alloc.h>
  29. #endif
  30.  
  31. #include <conio.h>
  32. #include <time.h>
  33. #ifdef __TURBOC__
  34. #include <graphics.h>
  35. #endif
  36. #include "uw.h"
  37. #include "uw_globx.h"
  38. #include "uw_keys.h"
  39.  
  40. #define NUM_WINS 26
  41.  
  42. typedef struct fields_struct                        /* structure for field input to the    */
  43. {                                                                                /* order form function!                            */
  44.     int        num_fields;                                            /* total number of fields                        */
  45.     char    *input[10];                     /* strings for the result                        */
  46.     char    *mask[10];                      /* masks for display on the screen    */
  47.     char    *template[10];                  /* tempatess for validation                    */
  48.     int        x[10];                          /* positions for the input                    */
  49.     int        y[10];
  50.     int        strip[10];                      /* strip masks on result?                        */
  51. } FIELDS;
  52.  
  53.  
  54. /*----------------- global variables for the demo program ------------------*/ 
  55. WINDOW    Main_wn, Print_wn[2];
  56. WINDOW     Back_wn, *Back_wnp = &Back_wn;
  57. MENU        Top_menu, *Top_mnp = &Top_menu;
  58. MENU    Terminal_menu, Setup_menu, Window_menu, Files_menu;
  59. MENU        *Drop_mnps[4];
  60.  
  61. int        GraphDriver;        /* The Graphics device driver        */
  62. int        GraphMode;        /* The Graphics mode value        */
  63. int        ErrorCode;        /* Reports any graphics errors        */
  64.  
  65. uchar     *Font8x14;
  66. PRINT     Printer1, Printer2;
  67. char         *Enque_strs[] =
  68.                 {
  69.                     "EnQue Software",
  70.                     "Route 1, Box 116C",
  71.                     "Pleasant Hill, MO, 64080",
  72.                     "24-Hour BBS (816) 353-0991",
  73.                     "Voice/Fax (816) 329-6670",
  74.                     "(Voice 5-10pm and weekends)"
  75.                 };
  76. char        Name[40], Address[40], City[30], State[10],
  77.                 Zip[10], Phone[20], Password[10];
  78.  
  79.  
  80. /*------------------------ prototypes for the program ----------------------*/
  81. void init_g( void );
  82. void end_g( void );
  83. void show_graphics( void );
  84. void wn_3d_plst( int c, int r, char *str, WINDOW *wnp );
  85. void wn_line_demo( void );
  86. void wn_entry_demo( void );
  87. void wn_color_demo( void );
  88. void wn_create_demo( void );
  89. void wn_scroll_demo( void );
  90. void wn_prompt( char *prompt );
  91. void wait( void );
  92. void title_screen( void );
  93. int wn_menu_demo( void );
  94. int background_func();
  95. void wn_change_att( int new_att, int old_att, WINDOW *wnp );
  96. void wn_font_demo( void );
  97. void wn_print_demo( void );
  98. void disp_print_stats( PRINT *p, int mode, WINDOW *wnp );
  99.                             
  100.  
  101. /*********/
  102. /* ~main */
  103. /*       ********************************************************************/
  104. /****************************************************************************/
  105. int main()
  106. {
  107.     int i, r, end_flag = 0, mode_switch = 0;
  108.     WINDOW *wnp;
  109.     char far *dummy;
  110.  
  111.     init_video(80, 25);
  112.     init_mouse();
  113.     init_clock(0x3333);
  114.     wnp = &Main_wn;
  115.     wn_create( 0, 3, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, wnp );
  116.     wn_color( YELLOW, BLUE, wnp );
  117.     wn_bdr_color( YELLOW, BLUE, wnp );
  118.     wn_name("Main_wn", wnp);
  119.     add_window(wnp);
  120.     title_screen();
  121.     wn_plst( CENTERED, (V_rows / 2) - 1, "Welcome to the UltraWin Library!", wnp );
  122.     if( Ega )
  123.         wn_plst( CENTERED, 3, "UltraWin detects the presence of an EGA compatible board", wnp);
  124.     else if( Vga )
  125.         wn_plst( CENTERED, 3, "UltraWin detects the presence of a VGA compatible board", wnp);
  126.     wait();
  127.  
  128.     wn_clear(wnp);
  129.     wn_color( BLUE, LIGHTGRAY, wnp );
  130.  
  131.     wn_plst(1, 0, "    Speed it one of many features incorporated into the UltraWin Library.     ", wnp );
  132.     wn_plst(1, 1, "   Here is a list of the main features, all of which will be demonstrated!    ", wnp );
  133.  
  134.     wn_color( YELLOW, BLUE, wnp );
  135.     wn_hline(2,SGL_BDR,wnp);
  136.     r = 3;
  137.     wn_plst(0, r++, "1) Complete range of windowing functions to dynamically create, update,", wnp );
  138.     wn_plst(0, r++, "   move, and destroy an unlimited number of windows.", wnp );
  139.     wn_plst(0, r++, "2) A Window Manager that will handle all the hard work when multiple", wnp );
  140.     wn_plst(0, r++, "   windows are on the screen.", wnp );
  141.     wn_plst(0, r++, "3) Each window is fully buffered. Output to a window can take place at any", wnp );
  142.     wn_plst(0, r++, "   time, even if another window overlaps it.  This is perhaps, the", wnp );
  143.     wn_plst(0, r++, "   most impressive feature. Windows can scroll output even if overlapped!", wnp );
  144.     wn_plst(0, r++, "4) Powerful string and data entry capabilities.", wnp );
  145.     wn_plst(0, r++, "5) Powerful menuing capability with full mouse support!", wnp );
  146.     wn_plst(0, r++, "6) The library supports virtually any video board, including 43/50", wnp );
  147.     wn_plst(0, r++, "   row EGA/VGA mode. It even works with non-standard modes i.e. 132*60.", wnp );
  148.     wn_plst(0, r++, "7) UltraWin 2.10 now works in EGA/VGA graphics mode and has user defined", wnp );
  149.     wn_plst(0, r++, "   font capability in both text and graphics modes!", wnp );
  150.     wn_plst(0, r++, "8) EGA/VGA palette control and blink enable/disable to allow all 16", wnp );
  151.     wn_plst(0, r++, "   background colors without foreground blinking.", wnp );
  152.     wn_plst(0, r++, "9) UltraWin 2.10 also has dynamic printer queues that can be either ram", wnp );
  153.     wn_plst(0, r++, "   or disked based and can print to multiple devices in the background!", wnp );
  154.     wn_hline(r,SGL_BDR,wnp);
  155.     wait();
  156.  
  157.     while( !end_flag )
  158.     {
  159.         wn_clear(wnp);
  160.         if( mode_switch )
  161.             show_graphics();
  162.         wn_color( BLUE, LIGHTGRAY, wnp );
  163.         r = 3;
  164.         wn_3d_plst(13, r++, "A) Color/Palette Control", wnp ), r++;
  165.         wn_3d_plst(13, r++, "B) Window Creation      ", wnp ), r++;
  166.         wn_3d_plst(13, r++, "C) Text Line Drawing    ", wnp ), r++;
  167.         wn_3d_plst(13, r++, "D) Window Scrolling     ", wnp ), r++;
  168.         wn_3d_plst(13, r++, "E) Data Entry           ", wnp ), r++;
  169.         r = 3;
  170.         if( EgaVga )
  171.         {
  172.             if( Graphics )
  173.                 wn_3d_plst(43, r++, "F) Switch to Text       ", wnp ), r++;
  174.             else
  175.                 wn_3d_plst(43, r++, "F) Switch to Graphics   ", wnp ), r++;
  176.         }else
  177.                 wn_3d_plst(43, r++, "F) N/A                  ", wnp ), r++;
  178.         wn_3d_plst(43, r++, "G) Drop-down Menus      ", wnp ), r++;
  179.         wn_3d_plst(43, r++, "H) EGA/VGA Text Fonts   ", wnp ), r++;
  180.         wn_3d_plst(43, r++, "I) Print Capabilities   ", wnp ), r++;
  181.         wn_3d_plst(43, r++, "J) All of the Above     ", wnp ), r++;
  182.         r++;
  183.         wn_3d_plst(28, r++, "Q) Quit Demonstration   ", wnp );
  184.  
  185.         wn_prompt("Select desired demo to execute...");
  186.         wn_color( LIGHTGRAY, BLUE, wnp );
  187.         if( mode_switch )
  188.         {
  189.             G_opt = OFF;
  190.             wn_clear(wnp);
  191.             G_opt = ON;
  192.             mode_switch = 0;
  193.         }
  194.         switch( toupper(Event.key) )
  195.         {
  196.             case 'Q':    case 27: end_flag = 1; break;
  197.  
  198.             case 'A': wn_color_demo();  break;
  199.             case 'B': wn_create_demo(); break;
  200.             case 'C': wn_line_demo();   break;
  201.             case 'D': wn_scroll_demo(); break;
  202.             case 'E': wn_entry_demo();  break;
  203.  
  204.             case 'F':
  205.                 if( EgaVga )
  206.                 {
  207.                     if( Graphics )
  208.                     {
  209.                         if( Graphics )
  210.                             end_g();
  211.                         Graphics = 0;
  212.                         init_video(80,25);
  213.                         end_mouse();
  214.                         init_mouse();
  215.                     }else{
  216.                         init_uw_graphics( 640, 350, 14, 14, -1, -1 );
  217.                         end_mouse();
  218.                         init_mouse();
  219.                         if( Graphics )
  220.                             init_g();
  221.                         mode_switch = 1;
  222.                     }
  223.                 }
  224.                 break;
  225.             case 'G': wn_menu_demo();   break;
  226.             case 'H': wn_font_demo();   break;
  227.             case 'I': wn_print_demo();  break;
  228.  
  229.             case 'J':
  230.                 wn_color_demo();
  231.                 wn_create_demo();
  232.                 wn_line_demo();
  233.                 wn_scroll_demo();
  234.                 wn_entry_demo();
  235.                 wn_menu_demo();
  236.                 wn_font_demo();
  237.                 wn_print_demo();
  238.                 break;
  239.         }
  240.     }
  241.     if( Graphics )
  242.         end_g();
  243.     wn_destroy(wnp);
  244.     end_clock();
  245.     end_mouse();
  246.     end_video();
  247. }
  248.  
  249. /***********/
  250. /* ~init_g */
  251. /*         ******************************************************************/
  252. /****************************************************************************/
  253. void init_g( void )
  254. {
  255. #ifdef __TURBOC__
  256.     int xasp, yasp;            /* Used to read the aspect ratio*/
  257.  
  258.     registerbgidriver(EGAVGA_driver);
  259.  
  260.     GraphDriver = EGA;         /* Request auto-detection    */
  261.     GraphMode = EGAHI;
  262.     initgraph( &GraphDriver, &GraphMode, "" );
  263.     ErrorCode = graphresult();        /* Read result of initialization*/
  264.     if( ErrorCode != grOk ){        /* Error occured during init    */
  265.         printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
  266.         exit( 1 );
  267.     }
  268. #endif
  269. #ifdef M_I86
  270.     _setvideomode(_ERESCOLOR);
  271. #endif
  272. }
  273. /*** end of init_g ***/
  274.  
  275. /**********/
  276. /* ~end_g */
  277. /*        *******************************************************************/
  278. /****************************************************************************/
  279. void end_g( void )
  280. {
  281. #ifdef __TURBOC__
  282.     closegraph();
  283. #endif
  284. #ifdef M_I86
  285.     _setvideomode(_DEFAULTMODE);
  286. #endif
  287. }
  288. /*** end of end_g ***/
  289.  
  290. /******************/
  291. /* ~show_graphics */
  292. /*                ***********************************************************/
  293. /* This routine simply show that we really are in graphics mode!!!!         */
  294. /****************************************************************************/
  295. void show_graphics( void )
  296. {
  297.     int i, x;
  298.  
  299.     for( x = i = 0; i < 640; i += 4, x++ )
  300.         setcolor(x % 16), moveto(320, 175), lineto( i, 50 );
  301.     for( x = i = 0; i < 300; i += 4, x++ )
  302.         setcolor(x % 16), moveto(320, 175), lineto( 639, 50 + i );
  303.     for( x = i = 0; i < 640; i += 4, x++ )
  304.         setcolor(x % 16), moveto(320, 175), lineto(640 - i, 349 );
  305.     for( x = i = 0; i < 300; i += 4, x++ )
  306.         setcolor(x % 16), moveto(320, 175), lineto( 0, 350 - i );
  307. }
  308. /*** end of show_graphics ***/
  309.  
  310. /***************/
  311. /* ~wn_3d_plst */
  312. /*             **************************************************************/
  313. /* This is specifically for the demo menu....                               */
  314. /****************************************************************************/
  315. void wn_3d_plst( int c, int r, char *str, WINDOW *wnp )
  316. {
  317.     push(wnp->att);
  318.     wn_color( BLACK, BLUE, wnp );
  319.     mv_cs( c + 1, r + 1, wnp );
  320.     wn_qch( strlen(str), 223, wnp );
  321.     mv_cs( c + strlen(str), r, wnp );
  322.     wn_ch(220, wnp);
  323.     pop(wnp->att);
  324.     wn_plst( c, r, str, wnp );
  325. }
  326. /*** end of wn_3d_plst ***/
  327.  
  328. /*****************/
  329. /* ~wn_line_demo */
  330. /*               ************************************************************/
  331. /****************************************************************************/
  332. void wn_line_demo( void )
  333. {
  334.     int i, t, x, y;
  335.     WINDOW wn;
  336.  
  337.     wn_clear(&Main_wn);
  338.     /*----------------- demonstrate line drawing capabilities ----------------*/
  339.     wn_prompt("UltraWin has several border styles...");
  340.     wn_create( 17, 7, 59, 19, SGL_BDR, WN_NORMAL, &wn );
  341.     wn_color( BLACK, CYAN, &wn );
  342.     wn_bdr_color( BLACK, CYAN, &wn );
  343.     wn_set(&wn);
  344.     for( t = 0; t < 3; t++ )
  345.     {
  346.         for( i = 0; i <= 4; i++ )
  347.         {
  348.             wn.bdr_style = i;
  349.             wn_border(&wn);
  350.             wait_ticks(  6L );
  351.         }
  352.     }
  353.     wn_prompt("UltraWin has line drawing capabilities....");
  354.     wn.bdr_style = SGL_BDR;
  355.     wn_border(&wn);
  356.  
  357.     wn_hline(2,DBL_BDR,&wn);
  358.     wait_ticks(  6L );
  359.     wn_hline(4,SGL_BDR,&wn);
  360.     wait_ticks(  6L );
  361.     wn_vline(4,DBL_BDR,&wn);
  362.     wait_ticks(  6L );
  363.     wn_hline(8,DBL_BDR,&wn);
  364.     wait_ticks(  6L );
  365.     wn_vline(40,SGL_BDR,&wn);
  366.     wait_ticks(  6L );
  367.     wn_hline(6,SGL_BDR,&wn);
  368.     wait_ticks(  6L );
  369.     wn_vline(22,SGL_BDR,&wn);
  370.     wait_ticks(  6L );
  371.     wait();
  372.     wn_clear(&wn);
  373.     wn_border(&wn);
  374.     wn_color( YELLOW, CYAN, &wn );
  375.     wn_color( RED, CYAN, &wn );
  376.     wn_plst( 0, 1, "  1     2     3     4     5     6     7 ", &wn );
  377.     wn_plst( 0, 4, "  8     9    10    11    12    13    14 ", &wn );
  378.     wn_plst( 0, 7, " 15     16   17    18    19    20    21 ", &wn );
  379.     wn_plst( 0,10, " 22     23   24    25    26    27    28 ", &wn );
  380.     wn_color( BLACK, CYAN, &wn );
  381.     for( x = 5; x < 40; x += 6 )
  382.         wn_vline(x, SGL_BDR, &wn);
  383.     for( y = 2; y < 11; y += 3 )
  384.         wn_hline(y, SGL_BDR, &wn);
  385.     wn_color( BLUE, LIGHTGRAY, &wn );
  386.     wn.inside = 0;
  387.     wn_plst( 0, 0, "   S     M     T     W     T     F     S   ", &wn );
  388.     wn.inside = 1;
  389.     wait();
  390.     wn_destroy(&wn);
  391. }
  392. /*** end of wn_line_demo ***/
  393.  
  394. /******************/
  395. /* ~wn_entry_demo */
  396. /*                ***********************************************************/
  397. /****************************************************************************/
  398. void wn_entry_demo( void )
  399. {
  400.     int            i, stat, end_flag = OFF,
  401.                     m_att = ((CYAN << 4) | YELLOW),
  402.                     wn_att = ((CYAN << 4) | WHITE),
  403.                     bdr_att = ((CYAN << 4) | BLACK);
  404.     char      buffer[80];
  405.     WINDOW    wn, *wnp = &wn;
  406.     FIELDS    f;
  407.  
  408.     wn_clear(&Main_wn);
  409. /*---------------------- demonstrate entry capabilities --------------------*/
  410.     wn_prompt("UltraWin has flexible data entry support...");
  411.  
  412.     f.input[0]        = Name;
  413.     f.x[0]                = 23, f.y[0] = 10, f.strip[0] = ON;
  414.     f.mask[0]            = "___________________________________";
  415.     f.template[0]    = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
  416.   f.input[1]        = Address;
  417.     f.x[1]                = 23, f.y[1] = 11, f.strip[1] = ON;
  418.     f.mask[1]     = "___________________________________";
  419.     f.template[1] = "***********************************";
  420.     f.input[2]        = City;
  421.     f.x[2]                = 23, f.y[2] = 12, f.strip[2] = ON;
  422.     f.mask[2]     = "____________________";
  423.   f.template[2] = "UAAAAAAAAAAAAAAAAAAA";
  424.   f.input[3]        = State;
  425.     f.x[3]                = 52, f.y[3] = 12, f.strip[3] = ON;
  426.     f.mask[3]     = "__";
  427.     f.template[3] = "UU";
  428.     f.input[4]        = Zip;
  429.     f.x[4]                = 62, f.y[4] = 12, f.strip[4] = ON;
  430.     f.mask[4]     = "_____";
  431.     f.template[4] = "#####";
  432.     f.input[5]        = Phone;
  433.     f.x[5]                = 23, f.y[5] = 13, f.strip[5] = OFF;
  434.     f.mask[5]     = "(___) ___-____";
  435.     f.template[5] = " ###  ### ####";
  436.     f.input[6]        = Password;
  437.     f.x[6]                = 23, f.y[6] = 14, f.strip[6] = ON;
  438.     f.mask[6]     = "________";
  439.     f.template[6] = "AAAAAAAA";
  440.  
  441.     wn_create(2, 4, 77, 23, DBL_BDR, WN_NORMAL, wnp);
  442.     wn.bdr_att = bdr_att;
  443.     wn.att = wn_att;
  444.     wn_name("< UltraWin Order Form >", wnp);
  445.     m_hide();
  446.     add_window(wnp);
  447.     for (i=0; i<6; i++)
  448.         wn_plst(2, i + 1, Enque_strs[i], wnp);
  449.  
  450.     wn_plst(4,   8, "Yes, I want to order UltraWin at $39.95.  Please mail to:", wnp);
  451.     wn_plst(10, 10, "        Name:", wnp);
  452.     wn_plst(10, 11, "     Address:", wnp);
  453.     wn_plst(10, 12, "        City:                      State:    Zip:", wnp);
  454.     wn_plst(10, 13, "       Phone:", wnp);
  455.     wn_plst(10, 14, "BBS Password:", wnp);
  456.  
  457.     wnp->att = m_att;
  458.     for (i=0; i<7; i++)
  459.     {
  460.         wn_plst(f.x[i], f.y[i], f.mask[i], wnp);
  461.         wn_plst(f.x[i], f.y[i], f.input[i], wnp);
  462.     }
  463.     wn_plst(6, 17, "Please enter the following fields, pressing PgDn when complete", wnp);
  464.     wnp->att = m_att;
  465.     f.num_fields = 7;
  466.     wnp->att = bdr_att;
  467.     wn_plst(38, 1, "UltraWin Libraries + Source", wnp);
  468.     wn_plst(38, 2, "  1) Large Model Libraries", wnp);
  469.     wn_plst(38, 3, "  2) Printed Documentation", wnp);
  470.     wn_plst(38, 4, "  3) Example Programs", wnp);
  471.     wn_plst(38, 5, "  4) Support Via the EnQue BBS", wnp);
  472.     wn_plst(38, 6, "  5) Full Source Code!", wnp);
  473.     wnp->att = wn_att;
  474.     m_show();
  475.     i = 0;
  476.     while (!end_flag)
  477.     {
  478.         mv_cs(f.x[i], f.y[i], wnp);
  479.         stat = wn_gets(f.input[i], f.mask[i], f.template[i],
  480.                                      m_att, f.strip[i], wnp);
  481.         switch(stat)
  482.         {
  483.             case KEY_UP:
  484.                 if (--i < 0)
  485.                     i = f.num_fields - 1;
  486.                 break;
  487.           case KEY_ENTER:
  488.                 if (++i >= f.num_fields)
  489.                   end_flag = ON;
  490.                 break;
  491.             case KEY_DN: case KEY_TAB:
  492.                 if (++i >= f.num_fields)
  493.                     i = 0;
  494.               break;
  495.             case KEY_PGUP: case KEY_PGDN:
  496.             case KEY_ESC: case -1:
  497.                 end_flag = ON;
  498.                 break;
  499.         }
  500.     }
  501.     m_hide(), remove_window(wnp), m_show();
  502. }
  503. /*** end of wn_entry_demo ***/
  504.  
  505. /******************/
  506. /* ~wn_color_demo */
  507. /*                ***********************************************************/
  508. /****************************************************************************/
  509. void wn_color_demo( void )
  510. {
  511.     int i, x, xs, ys, new_att, old_att;
  512.     char buff[81];
  513.     uchar palette[16];
  514.     WINDOW *wns[8], *wnp;
  515.     static char *names[8] = { "<< Window 0 >>", "<< Window 1 >>",
  516.      "<< Window 2 >>", "<< Window 3 >>", "<< Window 4 >>",
  517.      "<< Window 5 >>", "<< Window 6 >>", "<< Window 7 >>" };
  518.  
  519.     wn_clear(&Main_wn);
  520.     wn_prompt("Let's demonstrate UltraWin's color capabilities...");
  521.     for( i = 0; i < 8; i++ )
  522.         wns[i] = (WINDOW *) calloc(1, sizeof(WINDOW));
  523.     for( i = 0; i < 8; i++ )
  524.     {
  525.         wnp = wns[i];
  526.         xs = i * 3 + 12, ys = i + 5;
  527.         wn_create( xs, ys, xs + 31, ys + 9, SGL_BDR, WN_NORMAL, wnp );
  528.         wn_color( WHITE,  i % 8, wnp );
  529.         wn_bdr_color( WHITE, i % 8, wnp );
  530.         sprintf(buff, "<< Window %d >>", i + 1 );
  531.         wn_name(names[i], wnp);
  532.         add_window(wnp);
  533.         for( x = 0; x < 8; x++ )
  534.         {
  535.             sprintf(buff, "Window %d, Line %d", i, x );
  536.             wn_plst( 0, x, buff, wnp );
  537.         }
  538.     }
  539.     for( x = 0; x < 32; x++ )
  540.     {
  541.         for( i = 0; i < 8; i++ )
  542.         {
  543.             new_att = ((((x + i + 1) % 8)) << 4) | WHITE;
  544.             old_att = (((x + i) % 8) << 4) | WHITE;
  545.             wn_bdratt(new_att, wns[i]);
  546.             wn_change_att( new_att, old_att, wns[i] );
  547.         }
  548.     }
  549.     wn_prompt("We can bring any window to the Top...");
  550.     for( i = 7; i >= 0; i-- )
  551.         make_top_window(wns[random(7)]);
  552.     for( i = 7; i >= 0; i-- )
  553.         make_top_window(wns[i]);
  554.     if( EgaVga )
  555.     {
  556.         wn_prompt("We can change the EGA/VGA palette registers...");
  557.         read_palette_all(palette);
  558.         for( i = 0; i < 512; i++ )
  559.             write_palette( random(16), random(64) );
  560.         write_palette_all(palette);
  561.     }
  562.     for( i = 0; i < 8; i++ )
  563.         remove_window(wns[i]);
  564. }
  565. /*** end of wn_color_demo ***/
  566.  
  567. /*******************/
  568. /* ~wn_create_demo */
  569. /*                 **********************************************************/
  570. /****************************************************************************/
  571. void wn_create_demo( void )
  572. {
  573.     int i, j, x, xs, ys, xe, ye;
  574.     char buff[81];
  575.     WINDOW *wns[NUM_WINS], *wnp;
  576.  
  577.     wn_color( YELLOW, BLUE, &Main_wn );
  578.     wn_clear(&Main_wn);
  579.     for( i = 0; i < 10; i++ )
  580.     {
  581.         mv_cs(20, i + 4, &Main_wn);
  582.         wn_printf(&Main_wn, "This is line %d........", i + 1 );
  583.     }
  584.     wn_prompt("Let's dynamically allocate, create, and set 26 POPUP windows.");
  585.     for( x = 0; x < NUM_WINS; x++ )
  586.         if( (wns[x] = (WINDOW *) calloc(1, sizeof(WINDOW))) == NULL )
  587.             return;
  588.     x = 0;
  589.     for( i = 0; i < 5; i++ )
  590.     {
  591.         for( j = 0; j < 4; j++, x++ )
  592.         {
  593.             switch( j )
  594.             {
  595.                 case 0: xs =      i * 6; ys =      i + 3; break;
  596.                 case 1: xs = 60 - i * 6; ys =      i + 3; break;
  597.                 case 2: xs =      i * 6; ys = 20 - i;         break;
  598.                 case 3: xs = 60 - i * 6; ys = 20 - i;          break;
  599.             }
  600.             wnp = wns[x];
  601.             wn_create( xs, ys, xs + 19, ys + 5, SGL_BDR, WN_POPUP,wnp );
  602.             wn_color( WHITE, j + 2, wnp );
  603.             wn_bdr_color( WHITE, j + 2, wnp );
  604.             sprintf(buff, "<< Window %d >>", x + 1 );
  605.             wn_name(buff, wnp);
  606.             wn_set(wnp);
  607.             wn_plst(CENTERED, 0, buff, wnp);
  608.         }
  609.     }
  610.     for( i = 0; i < 12; i += 2, x++ )
  611.     {
  612.         wnp = wns[x];
  613.         xs = 32 - i * 2, ys = 12 - i / 2;
  614.         xe = 47 + i * 2, ye = 15 + i / 2;
  615.         wn_create(xs, ys, xe, ye, SGL_BDR, WN_POPUP, wnp);
  616.         wn_color( WHITE, i % 8, wnp );
  617.         wn_bdr_color( WHITE, i % 8, wnp );
  618.         sprintf(buff, "<< Window %d >>", x + 1 );
  619.         wn_name(buff, wnp);
  620.         wn_set(wnp);
  621.     }
  622.     wn_plst( CENTERED, 5, "Note that these are POPUP windows.", wnp );
  623.     wn_plst( CENTERED, 6, "Everything below them is saved.", wnp );
  624.     wn_plst( CENTERED, 7, "Watch closely as they are removed.", wnp );
  625.     wn_plst( CENTERED, 9, "<<< Don't blink or you will miss it >>>!", wnp );
  626.     wait();
  627.     while( x-- > 0 )
  628.         wn_destroy(wns[x]);
  629.     wn_color( LIGHTGRAY, BLUE, &Main_wn );
  630.     wait();
  631. }
  632. /*** end of wn_create_demo ***/
  633.  
  634. /*******************/
  635. /* ~wn_scroll_demo */
  636. /*                 **********************************************************/
  637. /****************************************************************************/
  638. void wn_scroll_demo( void )
  639. {
  640.     int i, t, x, a, r;
  641.     WINDOW wn, wn1, wn2;
  642.  
  643.     wn_clear(&Main_wn);
  644.     /*--------------------- demonstrate scrolling speed ----------------------*/
  645.     wn_prompt("UltraWin has full window scrolling capabilities....");
  646.     wn_create( 15, 9, 59, 17, SGL_BDR, WN_NORMAL, &wn );
  647.     wn_color( YELLOW, RED, &wn );
  648.     wn_bdr_color( YELLOW, RED, &wn );
  649.     wn_name("Scrolling Window 1", &wn);
  650.     add_window(&wn);
  651.     for( t = 0; t < 2; t++ )
  652.     {
  653.         for( i = 0; i < 100; i++ )
  654.         {
  655.             wn.att &= 0xf0;
  656.             wn.att |= random(16);
  657.             wn_st("UltraWin Library ", &wn );
  658.             if( t == 0 )
  659.             wait_ticks( 1L );
  660.         }
  661.         if( t == 0 )
  662.             wn_prompt("Too slow? Let's try it at full speed!");
  663.     }
  664.     /*------------------------- scroll up and down ---------------------------*/
  665.     wn_prompt("There's more. UltraWin can scroll down...");
  666.     wn_color( YELLOW, RED, &wn );
  667.     wn_clear(&wn);
  668.     for( i = 0; i < 7; i++ )
  669.     {
  670.         mv_cs( 0, i, &wn );
  671.         wn_printf(&wn, "Line %d.....", i + 1 );
  672.     }
  673.     mv_cs(0,0,&wn);
  674.     for( i = 0; i < 7; i++ )
  675.     {
  676.         wn_csr_up(1,&wn);
  677.         wait_ticks(  2L );
  678.     }
  679.     wn_prompt("or UltraWin can scroll up.");
  680.     wn_clear(&wn);
  681.     for( i = 0; i < 7; i++ )
  682.     {
  683.         mv_cs( 0, i, &wn );
  684.         wn_printf(&wn, "Line %d.....", i + 1 );
  685.     }
  686.     for( i = 0; i < 7; i++ )
  687.     {
  688.         wn_csr_dn(1,&wn);
  689.         wait_ticks(  2L );
  690.     }
  691.     /*-------------------------- scrolling regions ---------------------------*/
  692.     wn_prompt("You can also set a scrolling region within a window...");
  693.     wn_color( YELLOW, RED, &wn );
  694.     wn_clear(&wn);
  695.     for( i = 0; i < 7; i++ )
  696.     {
  697.         mv_cs( 0, i, &wn );
  698.         wn_printf(&wn, "Line %d.....", i + 1 );
  699.     }
  700.     wn_scroll_reg( 3, 6, &wn );
  701.     wn_color(WHITE, RED, &wn);
  702.     mv_cs(0, 3, &wn);
  703.     for( i = 0; i < 100; i++ )
  704.     {
  705.         wn_st("UltraWin ", &wn );
  706.         wait_ticks(  2L );
  707.     }
  708.  
  709.     /*-------------------------- scroll multiples ---------------------------*/
  710.     wn_prompt("UltraWin can scroll multiple windows concurrently!");
  711.     wn_create( 12, 12, 49, 18, SGL_BDR, WN_NORMAL, &wn1 );
  712.     wn_color( WHITE, GREEN, &wn1 );
  713.     wn_bdr_color( WHITE, GREEN, &wn1 );
  714.     wn_name("Scrolling Window 2", &wn1);
  715.     wn_create( 18, 4, 69, 14, SGL_BDR, WN_NORMAL, &wn2 );
  716.     wn_color( RED, BLACK, &wn2 );
  717.     wn_bdr_color( RED, BLACK, &wn2 );
  718.     wn_name("Scrolling Window 3", &wn2);
  719.  
  720.     add_window(&wn1);
  721.     add_window(&wn2);
  722.     for( t = 0; t < 2; t++ )
  723.     {
  724.         for( i = 0; i < 100; i++ )
  725.         {
  726.             wn_st("Window 1 output ",&wn);
  727.             wn_st("Window 2 output ",&wn1);
  728.             wn_st("Window 3 output ",&wn2);
  729.             if( t == 0 )
  730.                 wait_ticks(  1L );
  731.         }
  732.         if( t == 0 )
  733.             wn_prompt("Too slow? Let's try it at full speed!");
  734.     }
  735.     /*----------------- scroll multiples while moving! -----------------------*/
  736.     wn_prompt("UltraWin can scroll multiple windows while moving!");
  737.     for( i = 0; i < 50; i++ )
  738.     {
  739.         wn_st("Window 1 output ",&wn);
  740.         wn_st("Window 2 output ",&wn1);
  741.         wn_st("Window 3 output ",&wn2);
  742.         x = random(10);
  743.         if( x == 1 )
  744.         {
  745.             if( wn.pane.x_min > 0 )
  746.                 wn.pane.x_min--, wn.pane.x_max--, r = 1;
  747.         }
  748.         else if( x == 2 )
  749.         {
  750.             if( wn1.pane.y_min > 4 )
  751.                 wn1.pane.y_min--, wn1.pane.y_max--, r = 1;
  752.             if( wn1.pane.x_max < V_cols )
  753.                 wn1.pane.x_min++, wn1.pane.x_max++, r = 1;
  754.         }
  755.         else if( x == 3 )
  756.         {
  757.             if( wn2.pane.y_max < V_rows )
  758.                 wn2.pane.y_min++, wn2.pane.y_max++, r = 1;
  759.             if( wn2.pane.x_max < V_cols )
  760.                 wn2.pane.x_min++, wn2.pane.x_max++, r = 1;
  761.         }
  762.         if( r )
  763.         {
  764.             reset_all_masks();                    /* reset all masks and redraw all windows */
  765.             refresh_desktop();             /* since we are moving windows NOT on top */
  766.         }                               /* if the window was always on top, we can*/
  767.     }                                  /* simply use move_wn_up, etc...                    */
  768.     remove_window(&wn);
  769.     remove_window(&wn1);
  770.     remove_window(&wn2);
  771. }
  772. /*** end of wn_scroll_demo ***/
  773.  
  774. /**************/
  775. /* ~wn_prompt */
  776. /*            ***************************************************************/
  777. /****************************************************************************/
  778. void wn_prompt( char *prompt )
  779. {
  780.     WINDOW wn;
  781.  
  782.     wn_create( 0, 0, 79, 2, DBL_BDR, WN_NORMAL, &wn );
  783.     wn_color( RED, LIGHTGRAY, &wn );
  784.     wn_bdr_color( LIGHTGRAY, BLACK, &wn );
  785.     wn_set(&wn);
  786.     wn_plst( CENTERED, 0, prompt, &wn );
  787.     wait();
  788.     wn_destroy(&wn);
  789. }
  790. /*** end of wn_prompt ***/
  791.  
  792. /*********/
  793. /* ~wait */
  794. /*       ********************************************************************/
  795. /****************************************************************************/
  796. void wait( void )
  797. {
  798.     push(Main_wn.att);
  799.     wn_color( LIGHTGRAY, RED, &Main_wn );
  800.     mv_cs(0,21,&Main_wn);
  801.     wn_cleol(&Main_wn);
  802.     wn_plst(CENTERED, 21, "Hit any key to continue...", &Main_wn);
  803.     wait_event();
  804.     pop(Main_wn.att);
  805.     mv_cs(0,21,&Main_wn);
  806.     wn_cleol(&Main_wn);
  807. }
  808. /*** end of wn_prompt ***/
  809.  
  810. /*****************/
  811. /* ~title_screen */
  812. /*               ************************************************************/
  813. /* This routine does the UltraCom title screen, logo and subscription info    */
  814. /****************************************************************************/
  815. char    *Title_strs[10] =
  816. {
  817. " ██    ██  ██  ████████  ████████  ████████     ██     ██  ██  ███     ██   ",
  818. " ██▒   ██▒ ██▒  ▒▒██▒▒▒▒ ██▒▒▒▒██▒ ██▒▒▒▒██▒    ██▒    ██▒ ██▒ ████░   ██▒  ",
  819. " ██▒░  ██▒░██▒░  ░██▒░░░░██▒░░░██▒░██▒░░░██▒░   ██▒░   ██▒░██▒░██▒██░  ██▒░ ",
  820. " ██▒░  ██▒░██▒░   ██▒░   ██▒░  ██▒░██▒░  ██▒░   ██▒░   ██▒░██▒░██▒░██░ ██▒░ ",
  821. " ██▒░  ██▒░██▒░   ██▒░   ████████▒░████████▒░   ██▒░   ██▒░██▒░██▒░ ██░██▒░ ",
  822. " ██▒░  ██▒░██▒░   ██▒░   ██▒▒██▒▒▒░██▒▒▒▒██▒░   ██▒░   ██▒░██▒░██▒░  ████▒░ ",
  823. " ██▒░  ██▒░██▒░   ██▒░   ██▒░░██░░░██▒░░░██▒░   ██▒███ ██▒░██▒░██▒░  ████▒░ ",
  824. "  ██████▒▒░█████  ██▒░   ██▒░  ██  ██▒░  ██▒░    ███▒███▒▒░██▒░██▒░    ██▒░ ",
  825. "   ▒▒▒▒▒▒░░ ▒▒▒▒▒  ▒▒░    ▒▒░   ▒▒  ▒▒░   ▒▒░     ▒▒▒ ▒▒▒░░ ▒▒░ ▒▒░     ▒▒░ ",
  826. "    ░░░░░░   ░░░░░  ░░     ░░    ░░  ░░    ░░      ░░░ ░░░   ░░  ░░      ░░ "
  827. };
  828. char    *Wave_strs[7] =
  829. {
  830. "            Source Available          Extended Mode Support                 ",
  831. "                      EGA/VGA Downloadable Fonts             Small          ",
  832. " ┌─────────┐      ╔═ Menus═╗     [Data Entry]                  │            ",
  833. " │ Windows │      ║1) Small║        $12.34              Fast───┼───Flexible ",
  834. " └─────────┘      ║2) Fast ║        09/29/90                   │            ",
  835. "                  ╚════════╝     (123) 555-1212            Compatible       ",
  836. "   Buffered Windows  Background Printing     Mouse Support                  "
  837. };
  838. char    *Info_strs[5] =
  839. {
  840. "UltraWin! Version 2.10 by EnQue Software (Kevin Huck and Boyd Gafford)",
  841. "Please send $39.95 for printed documentation and full source code to:",
  842. "EnQue Software ",
  843. "Route #1, Box 116C ",
  844. "Pleasant Hill, Mo. 64080"
  845. };
  846. void title_screen( void )
  847. {
  848.     int             i, r, c, c1 = 7, c2 = (c1 + 9) % 16;
  849.     int                x_off = (V_cols / 2) - 39;
  850.     int                y_off = (V_rows / 2) - 8;
  851.     int                len = strlen(Wave_strs[0]);
  852.     int                w_off = 0;
  853.     WINDOW        u_wn, b_wn;
  854.     uchar            b = 0, *mask, *src;
  855.     char            temp_str[40];
  856.     uchar            palette_save[17];
  857.  
  858.     wn_create(x_off, y_off, x_off + 77, y_off + 13, DBL_BDR, WN_POPUP, &b_wn);
  859.     b_wn.att = b_wn.bdr_att = (c1 << 4) | WHITE;
  860.     wn_set( &b_wn);
  861.     wn_create(x_off, y_off, x_off + 77, y_off + 13, NO_BDR, WN_NORMAL, &u_wn);
  862.     u_wn.att = u_wn.bdr_att = (c1 << 4) | c2;
  863.     wn_set( &u_wn);
  864.   wn_border(&b_wn);
  865.     u_wn.scroll = b_wn.scroll = OFF;
  866.     mv_cs(1, 1, &u_wn);
  867.     wn_qch(len, ' ', &u_wn);
  868.     for (i=0; i<10; i++)
  869.         wn_plst(1, i + 2, Title_strs[i], &u_wn);
  870.     mv_cs(1, 12, &u_wn);
  871.     wn_qch(len, ' ', &u_wn);
  872.  
  873.     mask = b_wn.mask;
  874.     src =  u_wn.buff;
  875.     for( r = 0; r < b_wn.rows; r++ )
  876.         for( c = 0; c < b_wn.cols; c++, mask++, src+=2 )
  877.             if ( ((*src != ' ') && (*src != 0)) )
  878.                 *mask += 1;
  879.     b_wn.mask_on = ON;
  880.     for (i=0; i<5; i++)
  881.         wn_plst(CENTERED, 16 + i, Info_strs[i], &Main_wn);
  882.     if( EgaVga )
  883.         read_palette_all(palette_save);
  884.     while ( !check_key() )
  885.     {
  886.         if( !(Tics % 5) )
  887.         {
  888.             if( !(Tics % 10) )
  889.                 write_palette(random(15),random(64));
  890.             if ((++b) >= len)
  891.             {
  892.                 b = 0;
  893.                 c1 = (c1 + 1) % 8;
  894.                 c2 = (c1 + 9) % 16;
  895.                 b_wn.att = b_wn.bdr_att = (c1 << 4) | WHITE;
  896.                 wn_border(&b_wn);
  897.                 u_wn.att = (c1 << 4) | c2;
  898.                 mv_cs(1, 1, &u_wn);
  899.                 wn_qch(len, ' ', &u_wn);
  900.                 for (i=0; i<10; i++)
  901.                     wn_plst(1, i + 2, Title_strs[i], &u_wn);
  902.                 mv_cs(1, 12, &u_wn);
  903.                 wn_qch(len, ' ', &u_wn);
  904.                 if( ++w_off >= 6 )
  905.                     w_off = 0;
  906.                 write_palette(random(15),random(64));
  907.             }
  908.             for( i = 0; i < 7; i++ )
  909.             {
  910.                 mv_cs(0, i + w_off, &b_wn);
  911.                 if (len - b)
  912.                     wn_st_qty(&Wave_strs[i][b], len - b, &b_wn);
  913.                 if (b)
  914.                     wn_st_qty(&Wave_strs[i][0], b, &b_wn);
  915.             }
  916.         }
  917.     }
  918.     if( EgaVga )
  919.         write_palette_all(palette_save);
  920.     wait_event();
  921.     wn_clear(&u_wn);
  922.     wn_border(&b_wn);
  923.     for( i = 0; i < 7; i++ )
  924.         wn_plst(1, i + 3, &Wave_strs[i][0], &u_wn);
  925.     wait();
  926.     wn_clear(&Main_wn);
  927.     wn_destroy(&u_wn);
  928.     wn_destroy(&b_wn);
  929. }
  930.  
  931. /*****************/
  932. /* ~wn_menu_demo */
  933. /*               ************************************************************/
  934. /* This routine demonstrates UltraWin's menuing capabilities...                         */
  935. /* the main polling loop!                                                                                                        */
  936. /****************************************************************************/
  937. int wn_menu_demo( void )
  938. {
  939.     int id, i,
  940.             back_att    = (LIGHTGRAY << 4) | BLACK,
  941.             bdr_att        = (LIGHTGRAY << 4) | BLACK,
  942.             csr_att        = (CYAN << 4) | YELLOW,
  943.             first_att    = (LIGHTGRAY << 4) | RED;
  944.  
  945.     wn_clear(&Main_wn);
  946. /*--------------------- demonstrate menuing capabilities -------------------*/
  947.     wn_prompt("Use the arrow keys or your mouse to traverse the menu tree!");
  948.  
  949. /*-------------------------- create top menu -------------------------------*/
  950.     menu_create(0, 4, V_cols - 1, 3, M_HORIZONTAL,
  951.                             back_att, bdr_att, csr_att, first_att,
  952.                             NO_BDR, WN_NORMAL, Top_mnp);
  953.     item_add( "   Files   ", 1, 3, &Top_menu );
  954.     item_add( " Terminals ", 2, 1, &Top_menu );
  955.     item_add( "   Setup   ", 3, 3, &Top_menu );
  956.     item_add( "  Windows  ", 4, 2, &Top_menu );
  957.  
  958.     Drop_mnps[0] = &Files_menu;
  959.     Drop_mnps[1] = &Terminal_menu;
  960.     Drop_mnps[2] = &Setup_menu;
  961.     Drop_mnps[3] = &Window_menu;
  962. /*------------------------- create file menu -------------------------------*/
  963.     menu_create(0, 5, 21, 12, M_VERTICAL,
  964.         back_att, bdr_att, csr_att, first_att,
  965.         SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  966.     item_add( " Text Editor   Alt-E",    5, 6, &Files_menu );
  967.     item_add( " Hex Editor    Alt-H",    6, 1, &Files_menu );
  968.     item_add( " File Manager  Alt-F",    7, 1, &Files_menu );
  969.     item_add( " Calculator    Alt-C",    8, 1, &Files_menu );
  970.     item_add( " Dos Shell     Alt-O",    9, 5, &Files_menu );
  971.     item_add( " Quit          Alt-Q",10, 1, &Files_menu );
  972.  
  973. /*------------------------ create terminal menu ----------------------------*/
  974.     menu_create(11, 5, 32, 11, M_VERTICAL,
  975.      back_att, bdr_att, csr_att, first_att, SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  976.     item_add( " Add Terminal  Alt-T",     11, 1, &Terminal_menu );
  977.     item_add( " Settings      Alt-F6", 12, 1, &Terminal_menu );
  978.     item_add( " Receive File  Alt-F7", 13, 1, &Terminal_menu );
  979.     item_add( " Transmit File Alt-F8", 14, 1, &Terminal_menu );
  980.     item_add( " Comm Status   Alt-S",     15, 6, &Terminal_menu );
  981.  
  982. /*--------------------------- create setup menu ----------------------------*/
  983.     menu_create(22, 5, 43,10, M_VERTICAL,
  984.         back_att, bdr_att, csr_att, first_att, SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  985.     item_add( " Mouse Setup        ",    16, 1, &Setup_menu);
  986.     item_add( " Video Mode    Alt-V", 17, 1, &Setup_menu );
  987.     item_add( " Window Color  Alt-W",    18, 1, &Setup_menu );
  988.     item_add( " Border Color  Alt-B", 19, 1, &Setup_menu );
  989.  
  990. /*--------------------------- create window menu ---------------------------*/
  991.     menu_create(33, 5, 48, 9, M_VERTICAL,
  992.         back_att, bdr_att, csr_att, first_att,  SGL_BDR, WN_NORMAL, Drop_mnps[3]);
  993.     item_add( " Delete  Alt-D",    20, 1, &Window_menu );
  994.     item_add( " Size    Alt-S",    21, 1, &Window_menu );
  995.     item_add( " Move    Alt-M",    22, 1, &Window_menu );
  996.  
  997. /*------------------------------ let's roll --------------------------------*/
  998.     wn_create( 0, 4, V_cols - 1, V_rows - 4, SGL_BDR, WN_NORMAL, Back_wnp );
  999.     wn_color( WHITE, RED, Back_wnp );
  1000.     wn_bdr_color( WHITE, RED, Back_wnp );
  1001.     add_window(Back_wnp);
  1002.     wn_plst(0,0, "UltraWin is a powerful, easy to use window library", Back_wnp);
  1003.     wn_plst(0,1, "with flexible data entry and menu capabilities... ", Back_wnp);
  1004.  
  1005.     menu_set(Top_mnp);
  1006.     m_show();
  1007.     set_idle_func(background_func);
  1008.     id = menu_system(Top_mnp, Drop_mnps, 0);
  1009.     set_idle_func(NULL);
  1010.  
  1011.     m_hide();
  1012.     menu_restore(Top_mnp);
  1013.     menu_destroy(Top_mnp);                                                        /* destroy all menus!        */
  1014.     for( i = 0; i < 4; i++ )
  1015.         menu_destroy(Drop_mnps[i]);
  1016.     remove_window(Back_wnp);                                                    /* background window    */
  1017.     return(id);
  1018. }
  1019. /*** end of wn_menu_demo ***/
  1020.  
  1021. /********************/
  1022. /* ~background_func */
  1023. /*                  *********************************************************/
  1024. /* This is the function we pass set_idle_func to do the background stuff!     */
  1025. /* We just output to the Back_wnp global window piointer some colored text. */
  1026. /****************************************************************************/
  1027. int background_func()
  1028. {
  1029.     int att;
  1030.  
  1031.     if( !(Tics % 10) )
  1032.     {
  1033.         att = Back_wnp->att & 0x0f;                                            /* roll through colors  */
  1034.         att = (att + 1) % 16;
  1035.         if( att == RED )
  1036.             att = (att + 1) % 16;
  1037.         Back_wnp->att &= 0xf0;
  1038.         Back_wnp->att |= att;
  1039.         m_hide();
  1040.         wn_st("UltraWin Library. Power, Speed, Ease!   ", Back_wnp );
  1041.         m_show();
  1042.     }
  1043.     return(1);
  1044. }
  1045. /*** end of background_func ***/
  1046.  
  1047. /******************/
  1048. /* ~wn_change_att */
  1049. /*                ***********************************************************/
  1050. /* This routine changes the color of a window...                                        */
  1051. /* This demonstrates low level window control...                                                        */
  1052. /****************************************************************************/
  1053. void wn_change_att( int new_att, int old_att, WINDOW *wnp )
  1054. {
  1055.     int i, cnt;
  1056.     uchar *dest = wnp->buff;
  1057.     old_att  = get_att(old_att);
  1058.     new_att  = get_att(new_att);
  1059.  
  1060.     cnt = wnp->rows * wnp->cols;
  1061.     dest++;
  1062.     for( i = 0; i < cnt; i++, dest += 2 )
  1063.         if( *dest == old_att )
  1064.             *dest = new_att;
  1065.     wn_border( wnp );
  1066.     wn_rfsh( wnp );
  1067. }
  1068. /*** end of wn_change_att ***/
  1069.  
  1070. /*****************/
  1071. /* ~wn_font_demo */
  1072. /*               ************************************************************/
  1073. /* This routine shows the various font capabilities in EGA/VGA...                      */
  1074. /****************************************************************************/
  1075. extern int G_opt;
  1076. void wn_font_demo( void )
  1077. {
  1078.     int i, r, c, x;
  1079.     WINDOW wn;
  1080.  
  1081.     push(Font_spacing);
  1082.     wn_clear(&Main_wn);
  1083.     if( (Font8x14 = (uchar *) calloc(256,14)) == NULL )
  1084.     {
  1085.         wn_printf(&Main_wn,"Sorry, not enough memory to allocate font!");
  1086.         wait();
  1087.         return;
  1088.     }
  1089.     if( !EgaVga )
  1090.     {
  1091.         wn_plst( CENTERED, 3,
  1092.             "Sorry, cannot demonstrate fonts on a non-EGA/VGA compatible adapter",
  1093.             &Main_wn );
  1094.         wait_ticks(18L*3L);
  1095.         return;
  1096.     }
  1097.     /*------------------- demonstrate font capabilities... -------------------*/
  1098.     wn_prompt("UltraWin has multiple text font capabilities....");
  1099.     wn_create( 30, 4, 50, 23, SGL_BDR, WN_NORMAL, &wn );
  1100.     wn_color( YELLOW, RED, &wn );
  1101.     wn_bdr_color( LIGHTGRAY, RED, &wn );
  1102.     wn_name("Font Window", &wn);
  1103.     add_window(&wn);
  1104.  
  1105.     G_opt = OFF;
  1106.     for( i = 0; i < 4; i++ )
  1107.     {
  1108.         wn_clear(&wn);
  1109.         switch( i )
  1110.         {
  1111.             case 1:
  1112.                 setmem( Font8x14, 256*14, 0 );
  1113.                 install_font( Font8x14, 0, 0, 256, 14, 0 );
  1114.                 rom8x8(0,0);
  1115.                 break;
  1116.             case 2:
  1117.                 rom8x14(0,0);
  1118.                 break;
  1119.             case 3:
  1120.                 wn_plst(CENTERED, 0, "Now we have 512 unique characters on the screen at one time!", &Main_wn);
  1121.                 load_font( Font8x14, "8x14icon.fnt" );
  1122.                 if( Vga )
  1123.                         rom8x14(0,1), rom8x14(1,1), mv_csr(0,80);
  1124.                 install_font( Font8x14, 1, 0, 256, 14, 0 );
  1125.                 set_block_ab(0,1);
  1126.                 break;
  1127.         }
  1128.         Font_spacing = 14;
  1129.         for( x = r = 0; r < 16; r++ )
  1130.             for( c = 0; c < 16; c++,x++ )
  1131.                 mv_cs( c, r, &wn ), wn_ch(x,&wn);
  1132.         if( Graphics )
  1133.             rom8x14(0,0);
  1134.         wait();
  1135.     }
  1136.     G_opt = ON;
  1137.     if( Vga )
  1138.         rom8x16(0,1), rom8x16(1,1), mv_csr(0,80);
  1139.   else
  1140.         rom8x14(0,0);
  1141.     set_block_ab(0,0);
  1142.     free(Font8x14);
  1143.     remove_window(&wn);
  1144.     pop(Font_spacing);
  1145. }
  1146. /*** end of wn_font_demo ***/
  1147.  
  1148. /******************/
  1149. /* ~wn_print_demo */
  1150. /*                ***********************************************************/
  1151. /*                                                                          */
  1152. /* Here we demostrate the capabilities of the background/dynamic printing   */
  1153. /* routines...                                                              */
  1154. /*                                                                          */
  1155. /* NOTE: All output will be directed to DOS files "out1.prt" & "out2.prt"   */
  1156. /*                                                                          */
  1157. /*                                                                          */
  1158. /* 1) First we set up a 1k ram based print queue that is allowed to "grow"  */
  1159. /*    up to 8k.  As the queue is emptied, it automatically shrinks,        */
  1160. /*    thereby minimizing memory usage. Note that the queue can be setup     */
  1161. /*    with an initial size equal to it's maximum size so that the dynamic   */
  1162. /*    sizing does not occur.                                                */
  1163. /*                                                                          */
  1164. /* 2) Next, we use a 128k disk based queue, requiring no memory, save a     */
  1165. /*    small amount of stack space, and print out the exact same data...     */
  1166. /*                                                                                                                                                    */
  1167. /* 3) Last, but not least, we will output to both the ram based and disk    */
  1168. /*    based queues at the same time!                                        */
  1169. /****************************************************************************/
  1170. void wn_print_demo( void )
  1171. {
  1172.     int i, r, c, pi, x;
  1173.     char buffer[81];
  1174.     ulong start, end;
  1175.     long secs;
  1176.     PRINT *p[2];
  1177.  
  1178.     wn_clear(&Main_wn);
  1179.     wn_prompt("UltraWin has background printing support!");
  1180.  
  1181.     wn_plst( CENTERED, 2, "Welcome to the UltraWin Printer Facilities!", &Main_wn );
  1182.     wn_plst( CENTERED, 4, "This demo will setup two printers, both    ", &Main_wn );
  1183.     wn_plst( CENTERED, 5, "outputting to DOS files.  The first one is ", &Main_wn );
  1184.     wn_plst( CENTERED, 6, "a dynamically sizing ram queue that will   ", &Main_wn );
  1185.     wn_plst( CENTERED, 7, "grow up to 8k, and shrink back to 1k when  ", &Main_wn );
  1186.     wn_plst( CENTERED, 8, "drained.  Ram based queues can be up to    ", &Main_wn );
  1187.     wn_plst( CENTERED, 9, "64k.  The second is a 32k disk based queue ", &Main_wn );
  1188.     wn_plst( CENTERED,10, "that requires virtually no memory at all.  ", &Main_wn );
  1189.     wn_plst( CENTERED,11, "Queues of this nature can be of any size up", &Main_wn );
  1190.     wn_plst( CENTERED,12, "to 2 Gigabytes!  First we will print 8k    ", &Main_wn );
  1191.     wn_plst( CENTERED,13, "to each queue separately, then to both     ", &Main_wn );
  1192.     wn_plst( CENTERED,14, "concurrently.  Watch the status update as  ", &Main_wn );
  1193.     wn_plst( CENTERED,15, "the data is printed in the background.     ", &Main_wn );
  1194.  
  1195. /*--------- initialize both a ram based and disk based print queue ---------*/
  1196.     if( !init_printer("out1.prt", NULL, 1024L, 8192L, &Printer1) )
  1197.         tone(1024,10);
  1198.     if( !init_printer("out2.prt", "disk.buf", 32768L, 32768L, &Printer2) )
  1199.         tone(1024,10);
  1200.     p[0] = &Printer1;
  1201.     p[1] = &Printer2;
  1202.     set_idle_func(print_in_bkgrnd);                /* wait event will call this for us */
  1203.     wait();
  1204.  
  1205.     for( i = 0; i < 2; i++ )
  1206.     {
  1207.         wn_create( 2, 6 + (i*8) + i, V_cols-3, 12 + (i*8) + i, SGL_BDR, WN_POPUP, &Print_wn[i] );
  1208.         wn_color( LIGHTGRAY, RED, &Print_wn[i] );
  1209.         wn_bdr_color( LIGHTGRAY, RED, &Print_wn[i] );
  1210.         sprintf( buffer, "Printer %d", i + 1 );
  1211.         wn_name(buffer, &Print_wn[i]);
  1212.         add_window(&Print_wn[i]);
  1213.     }
  1214. /*----------------------------- perform steps 1&2 --------------------------*/
  1215.     for( x = 0; x < 2; x++ )
  1216.     {
  1217.         wn_clear( &Main_wn);
  1218.         start = Tics;
  1219.         wn_plst( CENTERED, 2, "Queueing 8K bytes of data...", &Main_wn );
  1220.         p[x]->block_mode = 1;
  1221.         i = 0;
  1222.         disp_print_stats( p[x], 1, &Print_wn[x] );
  1223.         while( p[x]->cnt < 8000L )
  1224.         {
  1225.             sprintf( buffer, "This is line %4d \r", i++ );
  1226.             print_str( (uchar *) buffer, p[x] ), print_eol( p[x] );
  1227.             if( i % 100 )
  1228.                 disp_print_stats( p[x], 0, &Print_wn[x] );
  1229.             else
  1230.                 disp_print_stats( p[x], 1, &Print_wn[x] );
  1231.         }
  1232.         wn_st( "done!", &Main_wn );
  1233.         wn_plst( CENTERED, 3, "Now lets print the data...", &Main_wn );
  1234.         c = 0;
  1235.         while( (p[x]->cnt > 0L)  )
  1236.         {
  1237.             if( check_key() )
  1238.             {
  1239.                 get_key();
  1240.                 mv_cs( c++, 4, &Main_wn );
  1241.                 wn_ch( Event.key, &Main_wn );
  1242.             }
  1243.             print_in_bkgrnd();            /* this would be called automatically if we   */
  1244.                                                             /* called wait event. Otherwise, call it as   */
  1245.                                                             /* often as you can to perform printer output.*/
  1246.             disp_print_stats( p[x], 0, &Print_wn[x] );
  1247.         }
  1248.         disp_print_stats( p[x], 1, &Print_wn[x] );
  1249.         wn_plst( CENTERED, 3, "  Now lets print the data...done!  ", &Main_wn );
  1250.         end = Tics;
  1251.         mv_cs( 20, 1, &Main_wn );
  1252.         secs = ((end - start) * 100L) / 91L;
  1253.         wn_printf( &Main_wn, "Time: = ~%ld.%02ld seconds  ~%-5d bytes/sec",
  1254.             secs / 100L, secs % 100L, (int)(800000L/secs) );
  1255.         wait();
  1256.     }
  1257. /*------------------------------- perform steps 3 --------------------------*/
  1258.     wn_clear( &Main_wn);
  1259.     start = Tics;
  1260.     wn_plst( CENTERED, 2, "Queueing 8K bytes of data...", &Main_wn );
  1261.     i = 0;
  1262.     disp_print_stats( p[0], 1, &Print_wn[0] );
  1263.     disp_print_stats( p[1], 1, &Print_wn[1] );
  1264.     while( p[0]->cnt < 8000L )
  1265.     {
  1266.         sprintf( buffer, "This is line %4d \r", i++ );
  1267.         print_str( (uchar *) buffer, p[0] ), print_eol( p[0] );
  1268.         print_str( (uchar *) buffer, p[1] ), print_eol( p[1] );
  1269.         if( i % 100 )
  1270.         {
  1271.             disp_print_stats( p[0], 0, &Print_wn[0] );
  1272.             disp_print_stats( p[1], 0, &Print_wn[1] );
  1273.         }else{
  1274.             disp_print_stats( p[0], 1, &Print_wn[0] );
  1275.             disp_print_stats( p[1], 1, &Print_wn[1] );
  1276.         }
  1277.     }
  1278.     wn_st( "done!", &Main_wn );
  1279.     wn_plst( CENTERED, 3, "Now lets print the data...", &Main_wn );
  1280.     c = 0;
  1281.     while( (p[0]->cnt > 0L) || (p[1]->cnt > 0L) )
  1282.     {
  1283.         if( check_key() )
  1284.         {
  1285.             get_key();
  1286.             mv_cs( c++, 1, &Main_wn );
  1287.             wn_ch( Event.key, &Main_wn );
  1288.         }
  1289.         print_in_bkgrnd();                /* this would be called automatically if we   */
  1290.                                                             /* called wait event. Otherwise, call it as   */
  1291.                                                             /* often as you can to perform printer output.*/
  1292.         disp_print_stats( p[0], 0, &Print_wn[0] );
  1293.         disp_print_stats( p[1], 0, &Print_wn[1] );
  1294.     }
  1295.     disp_print_stats( p[0], 1, &Print_wn[0] );
  1296.     disp_print_stats( p[1], 1, &Print_wn[1] );
  1297.     wn_plst( CENTERED, 3, "  Now lets print the data...done!  ", &Main_wn );
  1298.     end = Tics;
  1299.     mv_cs( 20, 1, &Main_wn );
  1300.     secs = ((end - start) * 100L) / 91L;
  1301.     wn_printf( &Main_wn, "Time: = ~%ld.%02ld seconds  ~%-5d bytes/sec",
  1302.         secs / 100L, secs % 100L, (int)(1600000L/secs) );
  1303.     wait();
  1304. /*--------------------------------------------------------------------------*/
  1305.  
  1306.     remove_window(&Print_wn[0]);
  1307.     remove_window(&Print_wn[1]);
  1308.     end_printer( &Printer1 );
  1309.     end_printer( &Printer2 );
  1310.     wn_clear(&Main_wn);
  1311. }
  1312. /*** end of wn_print_demo ***/
  1313.  
  1314. /*********************/
  1315. /* ~disp_print_stats */
  1316. /*                   *******************************************************/
  1317. /*  This routine prints important variables in the printer structure to the*/
  1318. /*    desired window and is used primarily for debugging.  If the mode is    */
  1319. /*    1, all variables are printed, if 0, only the Read, Write, and Cnt are  */
  1320. /*    printed for speed.                                                     */
  1321. /*                                                                         */
  1322. /* Device:lpt1                                  Buffer:   disk.buf         */
  1323. /* Read  :    4343     Init Size:     2000      Active:1      CR  :1       */
  1324. /* Write :    6648     Max  Size:    32000      Halt  :1      LF  :2       */
  1325. /* Cnt   :    2345     Curr Size:    16000      Block :1      Xlat:0       */
  1326. /***************************************************************************/
  1327. void disp_print_stats( PRINT *p, int mode, WINDOW *wnp )
  1328. {
  1329.     mv_cs( 0, 1, wnp );
  1330.     wn_printf( wnp, "Read  :%8ld", p->read  );
  1331.     mv_cs( 0, 2, wnp );
  1332.     wn_printf( wnp, "Write :%8ld", p->write );
  1333.     mv_cs( 0, 3, wnp );
  1334.     wn_printf( wnp, "Cnt   :%8ld", p->cnt   );
  1335.     if( mode )
  1336.     {
  1337.         mv_cs( 0, 0, wnp );
  1338.         wn_printf( wnp, "Device:%-20s   Buffer:%-20s", p->device, p->buffer );
  1339.         mv_cs( 20, 1, wnp );
  1340.         wn_printf( wnp, "Init Size:%8ld    Active:%d    CR  :%d",
  1341.             p->init_que_size, p->active, p->cr_cnt );
  1342.         mv_cs( 20, 2, wnp );
  1343.         wn_printf( wnp, "Max  Size:%8ld    Halt  :%d    LF  :%d",
  1344.             p->max_que_size, p->halt, p->lf_cnt  );
  1345.         mv_cs( 20, 3, wnp );
  1346.         wn_printf( wnp, "Curr Size:%8ld    Block :%d    Xlat:%d",
  1347.             p->curr_que_size, p->block_mode, p->xlat_flag );
  1348.     }
  1349. }
  1350. /*** end of disp_print_stats ***/
  1351.  
  1352. /**** END OF FILE ****/
  1353.  
  1354.